package com.zhongli.devplatform.controller.common;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zhongli.devplatform.bean.SecurityHelper;
import com.zhongli.devplatform.dto.common.FeedbackDTO;
import com.zhongli.devplatform.po.common.ReadFeedbackPO;
import com.zhongli.devplatform.service.imp.common.ReadFeedbackService;
import com.zhongli.devplatform.utils.BeanCopierUtil;
import com.zhongli.devplatform.bean.Res;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author wy
 * @since 2020/7/30
 */
@Api(tags = "反馈app接口",description = "老师，学生，家长的反馈",value = "年级app接口")
@RestController
@RequestMapping("/feedback")
public class FeedbackController {

    @Resource
    private ReadFeedbackService feedbackService;

    @ApiOperation("反馈方法")
    @PostMapping("/save")
    public Res getAllClazzByGrade(@RequestBody FeedbackDTO feedbackDTO){
        ReadFeedbackPO feedbackPO = BeanCopierUtil.copy(feedbackDTO, ReadFeedbackPO.class);
        feedbackPO.setUserId(SecurityHelper.getCurrentUserId());
        feedbackService.save(feedbackPO);
        return Res.ok("success");
    }

    @ApiOperation("获取所有的历史反馈信息")
    @GetMapping
    public Res getCurrentUserFeedback(){
        Integer currentUserId = SecurityHelper.getCurrentUserId();
        List<ReadFeedbackPO> feedback = feedbackService.list(new QueryWrapper<ReadFeedbackPO>()
                .eq("user_id", currentUserId)
                .orderByDesc("create_time"));
        return Res.ok(feedback);
    }
}
